package com.kaifamiao.buffer;

/**
 * 1、int capacity()
 * 2、int length()
 * 3、append
 * 4、StringBuffer delete(int start, int end)
 * 5、int indexOf(String)
 *    int indexOf(String,int)
 * 6、int lastIndexOf(String)
 *    int lastIndexOf(String,int)
 * 7、insert
 * 8、StringBuffer reverse()
 */
public class TestStringBuffer1 {

    public static void main(String[] args) {

        StringBuffer buffer = new StringBuffer();
        // 获得缓冲区的容量
        System.out.println( "capacity: " + buffer.capacity() );
        // 获得缓冲区中已经存放的有效字符
        System.out.println( "length: " + + buffer.length() );

        // 在缓冲区末尾中追加字符
        buffer.append( '开' );
        buffer.append( '发' );
        buffer.append( '喵' );
        System.out.println( buffer );
        System.out.println( buffer.length() );

        buffer.append( 100 );
        System.out.println( buffer );
        System.out.println( buffer.length() );
        System.out.println( buffer.capacity() );

        buffer.append("kaifamiao");
        System.out.println( buffer );
        System.out.println( buffer.length() );
        System.out.println( buffer.capacity() );

        buffer.append( true );
        System.out.println( buffer );
        System.out.println( buffer.length() );
        System.out.println( buffer.capacity() );

        String sub = "100";
        int start = buffer.indexOf( sub );
        int end = start + sub.length();
        // 从字符缓冲区中删除[start, end)之间的字符
        buffer.delete( start, end );
        System.out.println( buffer );

        int index = buffer.indexOf( "喵" );
        buffer.deleteCharAt( index );
        System.out.println( buffer );

        // 在字符缓冲区指定位置插入给定内容
        buffer.insert(2, '喵' );
        System.out.println( buffer );

        buffer.replace( 3, 12 , "云创动力" );
        System.out.println( buffer );

        // 翻转缓冲区
        buffer.reverse();
        System.out.println( buffer );

    }

}
